package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Wish;
import cn.wolfcode.trip.base.mapper.WishMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IWishService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class WishServiceImpl implements IWishService {
    @Autowired
    private WishMapper wishMapper;

    @Override
    public Wish selectWishById(Long id) {
        return wishMapper.selectWishById(id);
    }

    @Override
    public void saveOrupdate(Wish w) {
        if (w.getId()==null){
            w.setRelTime(new Date());
            wishMapper.insert(w);
        }else{
            wishMapper.updateByPrimaryKey(w);
        }
    }

    @Override
    public PageInfo<?> selectAll(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<Wish> list = wishMapper.selectAll(qo);
        return new PageInfo<>(list);
    }
}
